import requests

#获取指定网页内的全部信息
def getPageData(url):
    #生成一个response对象
    myResponse = requests.get(url)
    #设置编码格式
    myResponse.encoding =myResponse.apparent_encoding
    # 打印响应后的状态
    print(myResponse.status_code)
    print(myResponse.text)

#获取指定的界面信息并保存到指定的文件当中
def createFile(url):
    # 生成一个response对象
    myResponse = requests.get(url)
    # 设置编码格式
    myResponse.encoding = 'utf-8'
    # 打印响应后的状态
    print('响应的状态码：'+str(myResponse.status_code))
    print('响应后的头部信息:' + str(myResponse.headers))
    print('响应的内容:' + myResponse.text)

    try:
        file = open("pagetext","w",encoding="utf-8")
        file.write(myResponse.text)
    except:
        print("Failed to create file!")
    else:
        file.close()





